package com.aiss.ws.activity;

import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.aiss.ws.R;
import com.aiss.ws.utils.Command;
import com.aiss.ws.utils.Futil;
import com.aiss.ws.utils.Url;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;

/**
 * Created by chenqiang on 16/5/17.
 */
@EActivity(R.layout.activity_information)
public class InformationActivity extends BaseActivity {

    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);

            if(msg.what==Command.HANDLECODE4){

                try {
                    JSONObject obj = (JSONObject) msg.obj;
                    JSONObject object = obj.getJSONObject("return_data");
                    user.setText(object.getString("name"));
                    name.setText(object.getString("trname"));
                    phone.setText(object.getString("phone"));
                    qq.setText(object.getString("qq"));
                    id.setText(object.getString("idcard"));
                    addr.setText(object.getString("addr"));

                } catch (JSONException e) {
                    e.printStackTrace();
                }
                linearlayout.setVisibility(View.VISIBLE);
            }
        }
    };

    @ViewById(R.id.linearlayout)
    LinearLayout linearlayout;

    @ViewById(R.id.user)
    TextView user;

    @ViewById(R.id.name)
    TextView name;

    @ViewById(R.id.phone)
    TextView phone;

    @ViewById(R.id.qq)
    TextView qq;

    @ViewById(R.id.id)
    TextView id;

    @ViewById(R.id.addr)
    TextView addr;

    @ViewById(R.id.title)
    TextView title_tv;


    @Click(R.id.back)
    void setBack(){
        finish();
    }

    @AfterViews
    void init(){
        title_tv.setText("个人资料");
    }

    @Override
    protected void onResume() {
        super.onResume();
        HashMap<String,String> hashMap = new HashMap<>();
        hashMap.put("type","gain");
        Futil.xutils(Url.INFORMATION,hashMap,handler, Command.HANDLECODE4);
    }


    /**
     * 账号
     */
    @Click(R.id.user_rel)
    void setUser(){
        ChangeInformationActivity_.intent(this).extra("type",0).extra("content",user.getText().toString()).start();
    }
    /**
     * 手机
     */
    @Click(R.id.phone_rel)
    void setPhone(){
        ChangeInformationActivity_.intent(this).extra("type",1).extra("content",phone.getText().toString()).start();
    }

    /**
     * qq
     */
    @Click(R.id.qq_rel)
    void setQq(){
        ChangeInformationActivity_.intent(this).extra("type",2).extra("content",qq.getText().toString()).start();
    }

    /**
     * 地址
     */
    @Click(R.id.addr_rel)
    void setAddr(){
        ChangeInformationActivity_.intent(this).extra("type",3).extra("content",addr.getText().toString()).start();
    }

}
